#!/bin/bash
#
# #########################################################
# Standard way to deploy PROD
#
# #########################################################
# Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
# #########################################################
#

# test filter-aq.property exist
filter=./bip-web/src/main/filters/filter-prod.properties
if [ -f $filter ]
then
  echo ok - found $filter
else
  echo you need $filter for that build...
  exit 1
fi

#
# be sure perform a full clean before start.
#
XBUILD=./bip-web/qooxdoo/bip/build
if [ -d $XBUILD ]
then
  echo "warn - found $XBUILD : should be under ./bip-web/target"
  rm -rf "$XBUILD"
else
  echo ok - not found $XBUILD
fi

XBUILD=./bip-web/qooxdoo/bip/source/script
if [ -d $XBUILD ]
then
  echo "warn - found $XBUILD : should be under ./bip-web/target"
  rm -rf "$XBUILD"
else
  echo ok - not found $XBUILD
fi

XBUILD=./bip-web/qooxdoo/bip/cache
if [ -d $XBUILD ]
then
  echo "warn - found $XBUILD : should be under ./bip-web/target"
  rm -rf "$XBUILD"
else
  echo ok - not found $XBUILD
fi

#
# Add a comment to cloudbees deployment
#
echo "please give a deploy comment:"
read deploycomment

echo "deploy comment: $deploycomment"

# first clean all.
echo "mvn clean"
mvn clean
if [ $? != 0 ]
then
  echo "ERROR occurred"
  read -p "Any key to continue ..."
  exit 1
fi

# then deploy
echo "mvn deploy"
mvn  -e -P prod install bees:deploy -Dbees.message="`whoami` - $deploycomment"
if [ $? != 0 ]
then
  echo "ERROR occurred"
  read -p "Any key to continue ..."
  exit 1
fi

echo "done"
exit 0
